using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace XProject.Control
{
    public partial class LunarDateBox : UserControl
    {      
        byte lunarDay;
        byte lunarMonth;
        bool completedInput;
        public string Text
        {
            get { return txtLunarDate.Text; }
            set { string[] arr = (value).Split(new char[] {'/' });
            if (arr[0].Length == 1) arr[0] = "0"+arr[0];
            txtLunarDate.Text = arr[0] + arr[1];
            }
        }
     
        public byte LunarDay
        {
            get { return lunarDay;}            
        }
        public byte LunarMonth
        {
            get { return lunarMonth; }
        }
        public bool CompletedInput
        {
            get { return completedInput; }
        }
        public bool IsValidInput()
        {
            if (txtLunarDate.Text.Length == 0 || txtLunarDate.Text.Length > 5) return false;

            return true;
        }

        public LunarDateBox()
        {
            InitializeComponent();
        }

        private void LunarDateBox_Load(object sender, EventArgs e)
        {

        }

        private void txtLunarDate_TextChanged(object sender, EventArgs e)
        {
            completedInput = false;
            string text=txtLunarDate.Text.Replace(" ","");           
            if (text.Length>=3 && !text.StartsWith("/") && !text.EndsWith("/"))
            {                
                string[] arr=txtLunarDate.Text.Split(new char[]{'/'});
                lunarDay = byte.Parse(arr[0]);
                lunarMonth = byte.Parse(arr[1]);
                completedInput = true;
            }
        }

        private void txtLunarDate_Leave(object sender, EventArgs e)
        {
            if (!completedInput)
            {
                MessageBox.Show("Invalid input for lunar date. Please try again");
                txtLunarDate.Focus();
                return;
            }
            
            if (lunarDay > 30) {
                MessageBox.Show("Lunar day must between 0 and 30");
                txtLunarDate.Focus();
                return;
            }
            if (lunarMonth< 1 || lunarMonth>12)
            {
                MessageBox.Show("Lunar month must between 1 and 12");
                txtLunarDate.Focus();
                return;
            }
            
        }

        private void txtLunarDate_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {

        }
    }
}
